# -*- coding: utf-8 -*-


import re
import sys
import warnings
warnings.filterwarnings("ignore")
import argparse
    
def openfile(filename):
    result = ""
    with open(filename,'r',encoding="utf-8") as f:
        result = f.read()
    return result


    
if __name__ == '__main__':
    # 配置支持的参数
    parser = argparse.ArgumentParser("生成 selector 代码")
    parser.add_argument('--select_event',help="设置是否为 select 事件")
    parser.add_argument('--click_event',help="设置是否为 click 事件")
    parser.add_argument('--pressed_drawable',help="设置点击 drawable")
    parser.add_argument('--normal_drawable',help="设置普通 drawable")
    
    if len(sys.argv) < 2:
        print('生成 selector 代码')
        print()
        print('\t--select_event: 设置是否为 select 事件')
        print('\t--click_event: 设置是否为 click 事件')
        print('\t--pressed_drawable: 设置点击 drawable')
        print('\t--normal_drawable: 设置普通 drawable')
    else:
        # 参数解析
        args = parser.parse_args()
        drawableHelper = openfile('template/DrawableHelper.kt')
        params = ''
        if args.select_event:
            params += " selectEvent = %s," % (args.select_event)
        if args.click_event:
            params += " clickEvent = %s," % (args.click_event)
        if args.pressed_drawable:
            params += " pressedOrSelectedDrawable = %s," % (args.pressed_drawable)
        if args.normal_drawable:
            params += " normalDrawable = %s," % (args.normal_drawable)
            
        params = params[0: len(params)-1] # 去除最后的逗号
        drawableHelper = drawableHelper.replace("[params]", params)
        print(drawableHelper)
        pass
